//! \file UiOther.c
//! \brief TODO: Document
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include <agar/core.h>
#include <agar/gui.h>

#include "UiWindowMain.h"
#include "UiMenu.h"
#include "UiConsole.h"

// =====[ Local Definitions ]===================================================

// =====[ Local DataTypes ]=====================================================

// =====[ Local Variables ]=====================================================
// static AG_Window *pWindow; TODO: remove

// =====[ Local Functions ]=====================================================
static void _UI_WindowAboutClose(AG_Event *event);

// =====[ Private (Internal) Methods ]==========================================

// =====[ Local Implementation ]================================================


// =============================================================================
// Implement: UI_WindowAboutNew
// -----------------------------------------------------------------------------
tERROR UI_WindowAboutNew(void)
{
  AG_Window *pWindow;
  AG_Button *pButton;

  // Create the window.
//  pWindow = AG_WindowNew(AG_WINDOW_MODAL | AG_WINDOW_KEEPABOVE | AG_WINDOW_NOMOVE | AG_WINDOW_NOHRESIZE | AG_WINDOW_NOVRESIZE);
  pWindow = AG_WindowNew(0);
  AG_WindowSetCaption(pWindow, "About");
  AG_WindowSetGeometry(pWindow, 0, 0, 200, 200);


  AG_LabelNew(pWindow, 0, "Dungeon Quest");
  AG_LabelNew(pWindow, 0, "Version: 0.0.1");
  AG_LabelNew(pWindow, 0, "http://www.blah.org/");

//  pButton = AG_ButtonNewFn(pWindow, 0, "OK", _UI_WindowAboutClose, "%p", pConsole);
  //pButton = AG_ButtonNewFn(pWindow, 0, "OK", _UI_WindowAboutClose, NULL);
  pButton = AG_ButtonNewFn(pWindow, 0, "OK", _UI_WindowAboutClose, "%p", pWindow);

//  // Attach the user interface menu.
//  UI_MenuNew((AG_Widget*)pWindow);              // Attach the dungeon quest menu.
//
//  // Divide the window vertically.
//  pPaneVert = AG_PaneNewVert(pWindow, AG_PANE_EXPAND);
//  {
//    // Divide the left pane horizontally.
//    pPaneHoriz = AG_PaneNewHoriz(pPaneVert->div[0], AG_PANE_EXPAND);
//    AG_LabelNew(pPaneHoriz->div[0], 0, "Left/Top");
//    pPixmap = AG_PixmapFromSurface(pPaneHoriz->div[1], 0, pMyImage);
//    AG_PaneMoveDividerPct(pPaneVert, 70);
//  }
//  UI_ConsoleNew(pPaneVert->div[1]);             // Attach the dungeon quest console.
//  AG_PaneMoveDividerPct(pPaneHoriz, 20);
//  AG_WindowMaximize(pWindow);                   // Use the entire host window.

  AG_WindowSetPosition(pWindow, AG_WINDOW_MC, 0);

  // Finally, show window.
  AG_WindowShow(pWindow);

  // TODO: error checking?
}


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
// -----------------------------------------------------------------------------
static void _UI_WindowAboutClose(AG_Event *event)
{
  AG_Window *pWindow = AG_PTR(1);

//  pWindow->

  AGWINCLOSE(pWindow);
//  AG_Window

  puts("Closing window");

//  dev.type = AG_DRIVER_CLOSE;
//  AG_ProcessEvent(NULL, &dev);

//  AGWINCLOSE(pWindow);
  /*
  AG_Console *pConsole = AG_PTR(1);
  char *pText;

  pText = AG_TextboxDupString(pTextBox);
  AG_ConsoleMsgS(pConsole, pText);
  AG_TextboxSetString(pTextBox, "");
  free(pText);
   */
}

